package volatileTest;

public class VolatileTask implements Runnable {
    /**
     * 如果不加volatile关键字会一直死循环
     */
    volatile boolean flag = true;
    int i = 0;

    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see Thread#run()
     */
    @Override
    public void run() {
        while (flag) {
            i++;
        }
        System.out.println("papap");
    }
}
